package logic

import (
	"context"
	"taobao/goods_srv/model/mysql"

	"taobao/goods_srv/internal/svc"
	"taobao/goods_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindUsernameInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFindUsernameInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindUsernameInfoLogic {
	return &FindUsernameInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FindUsernameInfoLogic) FindUsernameInfo(in *user.UserNameInfoRequest) (*user.UserNameInfoResponse, error) {
	// todo: 用户名查询信息

	u := mysql.UserWeek{}
	err := u.GetByUsernameInfo(in.Username)
	if err != nil {
		logx.Error("查询用户信息失败", err)
		return nil, err
	}

	return &user.UserNameInfoResponse{
		UserId:   int64(u.ID),
		Username: u.Username,
		Password: u.Password,
		Image:    u.Avatar,
	}, nil
}
